package com.disease.chronic.Mappers;

import com.disease.chronic.pojo.Indicators;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.sql.Date;
import java.util.List;

public interface IndicatorsMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Indicators record);

    int insertSelective(Indicators record);

    @Select("SELECT ID, NORMALSCOPE, INDICATORNAME, LASTUPDATETIME, LASTMEASURE, INDICATORUNIT, USERNAME " +
            "FROM \"INDICATORS\" WHERE USERNAME = #{username} ")
    @Results({
            @Result(column = "NORMALSCOPE", property = "normalScope"),
            @Result(column = "INDICATORNAME", property = "indicatorName"),
            @Result(column = "LASTUPDATETIME", property = "lastUpdateTime"),
            @Result(column = "LASTMEASURE", property = "lastMeasure"),
            @Result(column = "INDICATORUNIT", property = "indicatorUnit")
    })
    List<Indicators> selectAll(@Param("username") String username);

    Indicators selectByPrimaryKey(Integer id);

    @Select("SELECT ID, NORMALSCOPE, INDICATORNAME, LASTUPDATETIME, LASTMEASURE, INDICATORUNIT, USERNAME " +
            "FROM \"INDICATORS\" WHERE USERNAME = #{username} AND LASTUPDATETIME = #{day}")
    @Results({
            @Result(column = "NORMALSCOPE", property = "normalScope"),
            @Result(column = "INDICATORNAME", property = "indicatorName"),
            @Result(column = "LASTUPDATETIME", property = "lastUpdateTime"),
            @Result(column = "LASTMEASURE", property = "lastMeasure"),
            @Result(column = "INDICATORUNIT", property = "indicatorUnit")
    })
    List<Indicators> selectByUsernameAndDate(@Param("username") String username, @Param("day") Date day);

    @Select("SELECT ID, NORMALSCOPE, INDICATORNAME, LASTUPDATETIME, LASTMEASURE, INDICATORUNIT, USERNAME " +
            "FROM \"INDICATORS\" WHERE USERNAME = #{username} AND INDICATORNAME = #{indicatorName}")
    @Results({
            @Result(column = "NORMALSCOPE", property = "normalScope"),
            @Result(column = "INDICATORNAME", property = "indicatorName"),
            @Result(column = "LASTUPDATETIME", property = "lastUpdateTime"),
            @Result(column = "LASTMEASURE", property = "lastMeasure"),
            @Result(column = "INDICATORUNIT", property = "indicatorUnit")
    })
    Indicators selectByUsernameAndIndicatorName(@Param("username") String username, @Param("indicatorName") String indicatorName);

    int updateByPrimaryKeySelective(Indicators record);

    int updateByPrimaryKey(Indicators record);
}
